<template>
    <view class="institutional-page">
        <!-- 顶部导航栏 -->
        <view class="header-nav">
            <view class="nav-left" @tap="goBack">
                <text class="back-icon">‹</text>
            </view>
            <view class="nav-center">
                <text class="nav-title">机构管理</text>
            </view>
            <view class="nav-right">
                <view class="search-icon" @tap="searchOrganizations">
                    <text class="icon">🔍</text>
                </view>
                <view class="add-btn" @tap="addOrganization">
                    <text class="add-text">新增</text>
                </view>
            </view>
        </view>

        <!-- 机构统计信息 -->
        <view class="org-info">
            <text class="org-count">直属机构(个): {{ organizationCount }}</text>
        </view>

        <!-- 机构列表 -->
        <view class="org-list">
            <view class="org-item" v-for="(org, index) in organizationList" :key="index">
                <view class="org-left">
                    <text class="org-name">{{ org.name }}/{{ org.id }}</text>
                </view>
                <view class="org-right">
                    <view class="status-btn" :class="{ 'disabled': !org.status, 'enabled': org.status }" @tap="toggleStatus(org)">
                        <text class="status-text">{{ org.status ? '已启用' : '已停用' }}</text>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>


<script>
    import util from '@/common/utils'
    import mosoweTextScrollRow from '@/components/mosowe-text-scroll-row/mosowe-text-scroll-row.vue'
    import dayjs from 'dayjs';
    // #ifdef APP-PLUS
    import checkappupdate from '@/js_sdk/wonyes-checkappupdate/wonyes/checkappupdate.js'
    // #endif

    export default {
        components: {
            mosoweTextScrollRow,
        },
        data() {
            return {
                organizationCount: 16,
                organizationList: [
                    { name: '歌浴森', id: '89639', status: false },
                    { name: '森阳林', id: '89637', status: true },
                    { name: '林百万', id: '89635', status: true },
                    { name: '万龙', id: '89633', status: true },
                    { name: '龙梓古', id: '89631', status: true },
                    { name: '古基达', id: '89629', status: true },
                    { name: '达春胜', id: '89627', status: true },
                    { name: '胜于', id: '89625', status: true },
                    { name: '于友民', id: '89623', status: true },
                    { name: '于万水', id: '89621', status: true },
                    { name: '于千岁', id: '89619', status: true },
                    { name: '岁平安', id: '89617', status: true },
                    { name: '安泰和', id: '89615', status: true },
                    { name: '和顺达', id: '89613', status: true },
                    { name: '达利通', id: '89611', status: true },
                    { name: '通四海', id: '89609', status: true }
                ]
            }
        },
        onLoad() {
      

        },
        computed: {
            currNoticeDay() {
                 return dayjs(this.todayDate).format('MM月DD日');
            },
        },
        methods: {
            goBack() {
                uni.navigateBack();
            },
            searchOrganizations() {
                // 搜索机构
                uni.showModal({
                    title: '搜索机构',
                    content: '搜索功能待实现',
                    showCancel: false
                });
            },
            addOrganization() {
                // 新增机构
                uni.showModal({
                    title: '新增机构',
                    content: '新增机构功能待实现',
                    showCancel: false
                });
            },
            toggleStatus(org) {
                // 切换机构状态
                org.status = !org.status;
                const statusText = org.status ? '已启用' : '已停用';
                uni.showToast({
                    title: `${org.name} ${statusText}`,
                    icon: 'success'
                });
            }
        }
    
    };
</script>

<style lang="scss" scoped>
    .institutional-page {
        background-color: #f0f2f5;
        min-height: 100vh;

        // 顶部导航栏
        .header-nav {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 20rpx 30rpx;
            background: #fff;
            border-bottom: 1rpx solid #eee;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            z-index: 1000;

            .nav-left {
                width: 60rpx;
                height: 60rpx;
                display: flex;
                align-items: center;
                justify-content: center;

                .back-icon {
                    font-size: 48rpx;
                    color: #333;
                    font-weight: bold;
                }
            }

            .nav-center {
                flex: 1;
                text-align: center;

                .nav-title {
                    font-size: 36rpx;
                    font-weight: bold;
                    color: #333;
                }
            }

            .nav-right {
                display: flex;
                align-items: center;
                gap: 20rpx;

                .search-icon {
                    width: 60rpx;
                    height: 60rpx;
                    display: flex;
                    align-items: center;
                    justify-content: center;

                    .icon {
                        font-size: 32rpx;
                        color: #666;
                    }
                }

                .add-btn {
                    .add-text {
                        font-size: 28rpx;
                        color: #427AF5;
                        font-weight: 500;
                    }
                }
            }
        }

        // 机构统计信息
        .org-info {
            padding: 20rpx 30rpx;
            background: #f0f2f5;
          
            position: fixed;
            top: 100rpx;
            left: 0;
            right: 0;
            z-index: 999;

            .org-count {
                font-size: 28rpx;
                color: #333;
            }
        }

        // 机构列表
        .org-list {
            padding: 0 30rpx;
            background: transparent;
            margin-top: 180rpx;

            .org-item {
                display: flex;
                align-items: center;
                justify-content: space-between;
                padding: 30rpx 20rpx;
                background: #fff;
                border-radius: 12rpx;
                margin-bottom: 12rpx;
                box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.06);

                &:last-child {
                    margin-bottom: 0;
                }

                .org-left {
                    flex: 1;

                    .org-name {
                        font-size: 28rpx;
                        color: #333;
                        
                    }
                }

                .org-right {
                    .status-btn {
                        padding: 8rpx 20rpx;
                        border-radius: 10rpx;
                        font-size: 24rpx;
                        font-weight: 500;
                        transition: all 0.3s ease;
                        min-width: 80rpx;
                        text-align: center;

                        &.disabled {
                            background: #f5f5f5;
                            color: #999;
                        }

                        &.enabled {
                            background: #427AF5;
                            color: #fff;
                        }

                        .status-text {
                            font-size: 24rpx;
                        }
                    }
                }
            }
        }
    }
</style>